package pers.corvey.studyjava.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import pers.corvey.studyjava.model.json.SearchResultJson;
import pers.corvey.studyjava.service.SearchService;

@Controller
@RequestMapping("/resources")
public class ResourceController {

    @Autowired
    private SearchService searchService;

    @GetMapping(headers="Accept=text/html")
    public String show() {
        return "forward://html/showSearchResult.html";
    }
    
    @GetMapping
    @ResponseBody
    public List<SearchResultJson> search(@RequestParam("keyword") String keyword) {
        return searchService.search(keyword);
    }
    
}
